package com.team.easybuy.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.team.easybuy.entity.News;
import com.team.easybuy.entity.User;
import com.team.easybuy.service.NewsService;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/news")
public class NewsController {

    @Resource
    private NewsService newsService;

    @RequestMapping("/pageByNews")
    public PageInfo<News> pageByNews(@RequestParam Map<String, Object> params) {
        int pageNum = Integer.parseInt(params.get("pageNum").toString());
        int pageSize = Integer.parseInt(params.get("pageSize").toString());
        PageHelper.startPage(pageNum, pageSize);
        List<News> listNews = newsService.ListNews();
        return new PageInfo<>(listNews, 5);
    }

    @RequestMapping("/showNews/{id}")
    public News showNews(@PathVariable Integer id) {
        return newsService.findById(id);
    }
}
